package com.thb.pay.core.exception;

/**
 * 自定义异常
 */
public class RRException extends RuntimeException {
    // 未知异常->系统异常
    public static final int UNKNOWN_EXCEPTION = 4;
    public static final String UNKNOWN_MESSAGE = "unknown.error.";
    private static final long serialVersionUID = 1L;
    private String msg;
    private int code = 500;

    /**
     * 错误参数
     */
    private String[] args;

    public RRException(String msg, String... args) {
        super(msg);
        this.msg = msg;
        this.args = args;
    }

    public RRException(String msg, Throwable e) {
        super(msg, e);
        this.msg = msg;
    }

    public RRException(String msg, Throwable e, String... args) {
        super(msg, e);
        this.msg = msg;
        this.args = args;
    }
    public RRException(int code, String msg) {
        super(msg);
        this.msg = msg;
        this.code = code;
    }

    public RRException(int code, String msg, String... args) {
        super(msg);
        this.msg = msg;
        this.code = code;
        this.args = args;
    }

    public RRException(int code, String msg, Throwable e) {
        super(msg, e);
        this.msg = msg;
        this.code = code;
    }

    public RRException(int code, String msg, Throwable e, String... args) {
        super(msg, e);
        this.msg = msg;
        this.code = code;
        this.args = args;
    }

    public static RRException build(int code, String msg, Throwable e) {
        return new RRException(code, msg, e);
    }


    public static RRException build(int code, String msg, Throwable e, String... args) {
        return new RRException(code, msg, e, args);
    }

    public static RRException build(int code, String msg) {
        return new RRException(code, msg);
    }


    public static RRException build(int code, String msg, String... args) {
        return new RRException(code, msg, args);
    }

    public static RRException build(String msg) {
        return new RRException(msg);
    }

    public static RRException build(String msg, String... args) {
        return new RRException(msg, args);
    }

    public static RRException build(IBusinessException businessEx, Throwable e) {
        return new RRException(businessEx.getCode(), businessEx.getMessageKey(), e);
    }


    public static RRException build(IBusinessException businessEx, Throwable e, String... args) {
        return new RRException(businessEx.getCode(), businessEx.getMessageKey(), e, args);
    }

    public static RRException build(IBusinessException businessEx) {
        return new RRException(businessEx.getCode(), businessEx.getMessageKey());
    }

    public static RRException build(IBusinessException businessEx, String... args) {
        return new RRException(businessEx.getCode(), businessEx.getMessageKey(), args);
    }


    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String[] getArgs() {
        return args;
    }

    public void setArgs(String[] args) {
        this.args = args;
    }
}
